package com.iter.devbox.cassandra;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.cassandra.core.CassandraOperations;

public class CassandraConfigClient {

	private static final Logger LOG = LoggerFactory.getLogger(CassandraConfigClient.class);

	public static void main(String[] args) throws Throwable {
		 ApplicationContext context = new AnnotationConfigApplicationContext(CassandraConfig.class);
		 CassandraOperations cassandraOperations = context.getBean("cassandraTemplate", CassandraOperations.class);
		 
		 //插入数据
		 //cassandraOperations.insert(new Student(2, "David", 40));

		 //查询数据
		 String queryCQL = "select * from student";
		 
		 List<Student> studentList = cassandraOperations.select(queryCQL, Student.class);
		 for (Student student : studentList) {
			 System.out.println("result：\n" + student.getId() + "\n" + student.getName() + "\n" + student.getAge());
			 LOG.info("result：\n" + student.getId() + "\n" + student.getName() + "\n" + student.getAge());
		 }
	}
}